<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: appHeader"></head>
<body id="history-body" ontouchstart>
<div class="weui-form-preview">
    <div class="weui-form-preview__hd">
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">生产令号</label>
            <b class="weui-form-preview__item" th:text="${sheet.prodNo}"></b>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">图号</label>
            <b class="weui-form-preview__item" th:text="${sheet.drawNo}"></b>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">零件名称</label>
            <b class="weui-form-preview__item" th:text="${sheet.drawName}"></b>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">零件数量</label>
            <b class="weui-form-preview__item" th:text="${sheet.drawNum}"></b>
        </div>
    </div>
    <h2 th:if="${#lists.isEmpty(list)} and ${#lists.isEmpty(completeList)}" style="margin-top: 16px;text-align: center">查无记录</h2>
    <h2 th:if="${#lists.isEmpty(list)} and ${completeList.size() > 0}" style="margin-top: 16px;text-align: center">该零件已全部转序</h2>
    <div th:each="r : ${list}">
        <div class="weui-form-preview__bd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">工艺路线</label>
                <b class="weui-form-preview__item" th:text="${r.route}"></b>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">数量</label>
                <b class="weui-form-preview__item" th:text="${r.num}"></b>
            </div>
        </div>
        <div class="weui-form-preview__ft">
            <button type="button" class="weui-form-preview__btn weui-form-preview__btn_default"
                    th:onclick="|reject(${r.id})|">质检驳回
            </button>
            <button type="button" class="weui-form-preview__btn weui-form-preview__btn_primary"
                    th:onclick="|success(${r.id})|">质检合格
            </button>
        </div>
    </div>
</div>

<div id="pop-reject" class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="toolbar">
            <div class="toolbar-inner">
                <a href="javascript:void(0);" class="picker-button close-popup">关闭</a>
                <h1 class="title">驳回</h1>
            </div>
        </div>
        <div class="modal-content">
            <form id="reject-form">
                <input id="reject-id" type="hidden" name="id">
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell weui-cell_switch">
                        <div class="weui-cell__bd">作废</div>
                        <div class="weui-cell__ft">
                            <input class="weui-switch" type="checkbox" name="status" value="1">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__bd">
                            <textarea class="weui-textarea" name="reason" rows="3" placeholder="请输入驳回原因"></textarea>
                        </div>
                    </div>
                </div>
            </form>
            <div class="weui-btn-area">
                <a class="weui-btn weui-btn_primary" href="javascript:" id="btn-reject">确定</a>
            </div>
        </div>
    </div>
</div>

<div id="pop-success" class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="toolbar">
            <div class="toolbar-inner">
                <a href="javascript:void(0);" class="picker-button close-popup">关闭</a>
                <h1 class="title">合格</h1>
            </div>
        </div>
        <div class="modal-content">
            <form id="success-form">
                <input id="success-id" type="hidden" name="id">
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell weui-cell_switch">
                        <div class="weui-cell__bd">让步接收</div>
                        <div class="weui-cell__ft">
                            <input class="weui-switch" type="checkbox" name="yield" value="1">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__bd">
                            <textarea class="weui-textarea" name="result" rows="3" placeholder="请输入质检结果"></textarea>
                        </div>
                    </div>
                </div>
            </form>
            <div class="weui-btn-area">
                <a class="weui-btn weui-btn_primary" href="javascript:" id="btn-success">确定</a>
            </div>
        </div>
    </div>
</div>

<div th:include="include :: appFooter"></div>
<script th:inline="javascript">

    function reject(id) {
        $("#pop-reject").popup();
        $("#reject-id").val(id);
    }

    function success(id) {
        $("#pop-success").popup();
        $("#success-id").val(id);
    }

    $(function () {
        $("#btn-success").click(function (e) {
            let result = $("#success-form [name='result']").val();
            let yield =  $("#success-form [name='yield']");
            if (yield.prop("checked") && (result === undefined || result === null || result.replace(/[\r\n]/g, "") === '')) {
                $.box.toptip_w('请输入质检结果！');
                return;
            }
            $.operate.submit({
                url: ctx + 'assembly/success',
                data: new FormData($("#success-form")[0]),
                fun: function () {
                    location.href = ctx + "index";
                }
            });
        })

        $("#btn-reject").click(function (e) {
            let reason = $("#reject-form [name='reason']").val();
            if (reason === undefined || reason === null || reason.replace(/[\r\n]/g, "") === '') {
                $.box.toptip_w('请输入驳回原因！');
                return;
            }
            $.operate.submit({
                url: ctx + 'assembly/reject',
                data: new FormData($("#reject-form")[0]),
                fun: function () {
                    location.href = ctx + "index";
                }
            });
        })
    })

</script>
</body>
</html>